//
//  GTVideoViewController.m
//  SampleApp2
//
//  Created by GXHC on 2023/6/21.
//

#import "GTVideoViewController.h"
#import <AVKit/AVKit.h>
#import <AVFoundation/AVFoundation.h>

@interface GTVideoViewController ()
@property(nonatomic, strong, readwrite) AVPlayerViewController      *playerController;
@property(nonatomic, strong, readwrite)	AVPlayer                    *player;
@property(nonatomic, strong, readwrite)	AVAudioSession              *session;
@property(nonatomic, strong, readwrite)	NSString                    *urlString;
@end

@implementation GTVideoViewController

- (void)viewDidLoad {
	[super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
	self.view.backgroundColor = [UIColor whiteColor];
	_session = [AVAudioSession sharedInstance];
	[_session setCategory:AVAudioSessionCategoryPlayback error:nil];
	
	_player = [AVPlayer playerWithURL:[NSURL URLWithString:@"https://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4"]];
	_playerController = [[AVPlayerViewController alloc] init];
	_playerController.player = _player;
	_playerController.videoGravity = AVLayerVideoGravityResizeAspect;
	_playerController.allowsPictureInPicturePlayback = true;    //画中画，iPad可用
	_playerController.showsPlaybackControls = true;
	
	[self addChildViewController:_playerController];
	_playerController.view.translatesAutoresizingMaskIntoConstraints = true;    //AVPlayerViewController 内部可能是用约束写的，这句可以禁用自动约束，消除报错
	//self.view.bounds
	_playerController.view.frame = CGRectMake(0, 88, self.view.bounds.size.width, 300);
	[self.view addSubview:_playerController.view];
	[_playerController.player play];    //自动播放
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
